package com.example.zk2_lx.video;

import androidx.lifecycle.MutableLiveData;

import com.example.zk2_lx.entity.ResultEntity;
import com.example.zk2_lx.entity.VideoEntity;
import com.example.zk2_lx.mvvm.BaseRepo;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

public class VideoRepo extends BaseRepo {
    public void video(int page, int size, MutableLiveData<VideoEntity> success,MutableLiveData<String> fail){
        apiServer.video(page, size)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<VideoEntity>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(VideoEntity entity) {
                        success.postValue(entity);
                    }

                    @Override
                    public void onError(Throwable e) {
                        fail.postValue(e.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }
    public void love(int id, MutableLiveData<ResultEntity> loveSucc,MutableLiveData<String> loveFail){
        apiServer.love(id)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<ResultEntity>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(ResultEntity entity) {
                        loveSucc.postValue(entity);
                    }

                    @Override
                    public void onError(Throwable e) {
                        loveFail.postValue(e.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }
    public void nolove(int id, MutableLiveData<ResultEntity> noloveSucc,MutableLiveData<String> noloveFail){
        apiServer.nolove(id)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<ResultEntity>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(ResultEntity entity) {
                        noloveSucc.postValue(entity);
                    }

                    @Override
                    public void onError(Throwable e) {
                        noloveFail.postValue(e.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }
}
